#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N];
struct Node {
  int r, x;
  int id;
  bool operator<(Node a) const { return r < a.r; }
} q[N];
int ans[N];
int st[N], num;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, m) {
    cin >> q[i].r >> q[i].x;
    q[i].id = i;
  }
  sort(q + 1, q + m + 1);
  int l = 0;
  rep(i, 1, m) {
    while (l < q[i].r) {
      l++;
      int x = lower_bound(st + 1, st + num + 1, a[l]) - st;
      if (x > num) ++num;
      st[x] = a[l];
    }
    ans[q[i].id] = upper_bound(st + 1, st + num + 1, q[i].x) - st - 1;
  }
  rep(i, 1, m) cout << ans[i] << endl;
  return 0;
}